<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .content{ 
            width: 200px;
            height: 100px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
    <button id="btn">点击发送请求</button>
    <p class="content"></p>

    <script>
        let btn = document.getElementById("btn");
        let p1 = document.getElementsByClassName('content')[0]
        btn.onclick = function(){
            //创建对象
            const xhr = new XMLHttpRequest();
            //初始化 设置请求方法和url
            //  get请求传参 - 直接在url地址中传参
            xhr.open('GET','http://127.0.0.1:8085/server?a=10&b=20&c=30');
            //发送
            xhr.send();
            // 事件绑定 处理服务器端返回的结果
            xhr.onreadystatechange = function(){
                //判断服务器返回了所有结果
                if(xhr.readyState == 4){
                    //判断网页状态码为200
                    if(xhr.status >= 200 && xhr.status < 300){
                        //处理结果
                        // 1.获取响应行
                        // console.log(xhr.status); //状态码
                        // console.log(xhr.statusText); //状态字符串
                        // console.log(xhr.getAllResponseHeaders); //所有响应头
                        // console.log(xhr.response); //响应体
                        p1.innerHTML = xhr.response;
                    }
                }    
            }
            
        }
    </script>
</body>
</html>